﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Zyg.SSO.Web
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            Zyg.SSO.Core.Business.Account account = Zyg.SSO.Core.Business.Account.Load(UserEmail.Text);

            if (account == null)
            {
                Msg.Text = "用户不存在";
                return;
            }
            else
            {
                if (account.State != Zyg.SSO.Core.Business.AccountState.Active)
                {
                    Msg.Text = "当前用户暂不允许登录";
                    return;
                }
                Zyg.Security.SecurityHelper sh = new Zyg.Security.SecurityHelper();
                string encryptedPass = sh.ComputeMD5Hash(UserPass.Text);

                if (encryptedPass == account.Password)
                {
                    Session["User"] = account;

                    if (account.IsAdmin)
                    {
                        Response.Redirect("~/Admin/AccountManage.aspx");
                    }
                    else
                    {
                        Response.Redirect("~/Default.aspx");
                    }
                }
                else
                {
                    Msg.Text = "用户名或密码错误";
                }
            }
        }
    }
}
